/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.netbrain.util;

import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import mx.netbrain.model.Tree;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Julian
 */
public class FolderDataUtil extends ListDataModel<Tree> implements SelectableDataModel<Tree>, Serializable {
    
    /**
	 * 
	 */
	private static final long serialVersionUID = 8572740956174575163L;

	public FolderDataUtil() {
    }
    
    public FolderDataUtil(List<Tree> tree) {
        super(tree);
    }
    
    @Override
    public Object getRowKey(Tree tree) {
        return tree.getId();
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public Tree getRowData(String rowKey) {
        List<Tree> listTree = (List<Tree>) getWrappedData();
        for (Tree tree : listTree) {
            if (rowKey.equals(tree.getId().toString())) {
                return tree;
            }
        }
        return null;
    }
}
